import { Repository } from 'typeorm';
import { Provide } from '@midwayjs/decorator';
import { InjectEntityModel } from '@midwayjs/orm';
import { BaseService } from '@aipeli/midway-crud';
import { ShopUserEntity } from '../entity/user';

@Provide()
export class ShopUserService extends BaseService {
  @InjectEntityModel(ShopUserEntity)
  userModel: Repository<ShopUserEntity>;

  async getUser(id: number) {
    const user = await this.userModel.findOneBy({ id: id });
    console.log('访问自定义route: /admin/shop/user/get_User');
    return user;
  }

  // async list(query, option) {
  //   console.log(query);
  //   const { sql, sqlParams } = await this.buildQuerySql(query, option);
  //   console.log(sql, sqlParams);
  //
  //   const count = await this.nativeQuery(
  //     this.getQuerCountSql(sql),
  //     sqlParams
  //   );
  //   console.log(...count);
  //   const users = await this.nativeQuery(sql, sqlParams);
  //   console.log(
  //     '在user service打印记录条件',
  //     new RegExp(`(?<=FROM).*?(?=LIMIT)`).exec(sql)[0].trim()
  //   );
  //   return { query: count[0], option: users };
  // }
}
